﻿$(document).ready(function () {
    $("table[id^=ctl00_ContentPlaceHolder3_wgt_]").each(function () {
        if ($(this).attr('id').indexOf('_table') > -1)// by sanal on Jul 04, 2012 to make the widget UI better
        {
            $(this).attr('cellpadding', '0');
            $(this).attr('cellspacing', '0');
        }
    });
    // below line added by 'Imran Gani' on 20-Dec-2012, to make the dashboards UI with better alignment.
    $("td[id^=ctl00_ContentPlaceHolder3_td_WidgetChart_] span:first-child").css("display", "block").css("overflow", "hidden");
});
function GetBindValue(bind_id, hiddenfield, textboxid) {
    try {
        if (document.getElementById(hiddenfield) != null) {
            if (document.getElementById(textboxid) != null) {
                var SearchText = document.getElementById(textboxid).value;
                var xmlHttp_fb;
                try {
                    xmlHttp_fb = new XMLHttpRequest();
                }
                catch (e) {
                    try {
                        xmlHttp_fb = new ActiveXObject("Msxml2.XMLHTTP");
                    }
                    catch (e) {
                        try {
                            xmlHttp_fb = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch (e) {
                            return false;
                        }
                    }
                }
                xmlHttp_fb.onreadystatechange = function () {
                    if (xmlHttp_fb.readyState == 1) {
                        //document.getElementById("ctl00_fb_status").innerHTML = "<img src='Images/load.gif' border='0'></img>&nbsp;Submitting...";
                    }
                    if (xmlHttp_fb.readyState == 4) {
                        //if (xmlHttp_fb.responseText!="")
                        //{
                        var SearchValue = xmlHttp_fb.responseText;
                        document.getElementById(hiddenfield).value = SearchValue;

                        // }
                    }
                }
                xmlHttp_fb.open("GET", "LoadTips.aspx?PB=1&bnd=" + bind_id + "&SD=" + SearchText + "", true);
                xmlHttp_fb.send(null);
            }
        }
        //    xmlHttp_fb.open("GET","loadTips.aspx?fb=" + escape(fb)+"&IsMail=false&EMid="+emailid+"",true);
    }
    catch (Exxx) {

    }
}

function ShowOrdinates() {
    if (document.getElementById("ctl00_ContentPlaceHolder3_td_widget_ordinates") != null) {
        if (document.getElementById("ctl00_ContentPlaceHolder3_td_widget_ordinates").style.display == "none")
            document.getElementById("ctl00_ContentPlaceHolder3_td_widget_ordinates").style.display = "block";
        else
            document.getElementById("ctl00_ContentPlaceHolder3_td_widget_ordinates").style.display = "none";
    }
}
function UpdateListBoxes(type, Rowcount) {
    //alert("valueChanged");
    if (document.getElementById("ctl00_ContentPlaceHolder3_lst_" + type + "_axis") != null) {
        var List = document.getElementById("ctl00_ContentPlaceHolder3_lst_" + type + "_axis");
        if (document.getElementById("ctl00_ContentPlaceHolder3_axis_column_" + type + "_" + Rowcount) != null) {
            //alert("Dropdown found");
            var DropDown = document.getElementById("ctl00_ContentPlaceHolder3_axis_column_" + type + "_" + Rowcount);
            //alert("No of Items :"+ DropDown.options.length);
            if (DropDown.options.length > 0) {
                var ItemList = DropDown.options[DropDown.selectedIndex];
                if (ItemList != null) {
                    //alert("Selected : "+ ItemList);
                    List.options[Rowcount].text = ItemList.text;
                    List.options[Rowcount].value = ItemList.value;
                }
            }
        }
    }
}

function DeleteRow(rowcount) {
    //alert("Delete Clicked");
    if (document.getElementById("ctl00_ContentPlaceHolder3_hfAddClick") != null) {
        document.getElementById("ctl00_ContentPlaceHolder3_hfAddClick").value = "0";
    }
    if (document.getElementById("ctl00_ContentPlaceHolder3_hfDelClick") != null) {
        document.getElementById("ctl00_ContentPlaceHolder3_hfDelClick").value = rowcount;
    }
}

function AddNewRow() {
    //alert("Add Clicked");
    if (document.getElementById("ctl00_ContentPlaceHolder3_hfDelClick") != null) {
        document.getElementById("ctl00_ContentPlaceHolder3_hfDelClick").value = "";
    }
    if (document.getElementById("ctl00_ContentPlaceHolder3_hfAddClick") != null) {
        document.getElementById("ctl00_ContentPlaceHolder3_hfAddClick").value = "1";
    }
}

function showicon() {
    //alert("ShowIcon");
    var selectedvalue = "";
    try {
        if (document.getElementById("ctl00_ContentPlaceHolder3_ddlChartType") != null) {
            selectedvalue = document.getElementById("ctl00_ContentPlaceHolder3_ddlChartType").value;
            // alert(selectedvalue);

        }
        if (selectedvalue != "") {
            if (document.getElementById("ctl00_ContentPlaceHolder3_ImgIcon") != null) {
                document.getElementById("ctl00_ContentPlaceHolder3_ImgIcon").style.display = "block";
                document.getElementById("ctl00_ContentPlaceHolder3_ImgIcon").src = "Images/ChartImages/" + selectedvalue + ".GIF";
                document.getElementById("ctl00_ContentPlaceHolder3_hrefImgTooltip").href = "Images/ChartImages/ChartPreview/" + selectedvalue + ".jpg";
                if (selectedvalue == "table" || selectedvalue == "text") {
                    document.getElementById("ctl00_ContentPlaceHolder3_ImgIcon").style.display = "none";
                }
            }
        }
    }
    catch (err) {}
}

function UpdateEvent() {
    if (document.getElementById("ctl00_ContentPlaceHolder3_hfEventTriggered") != null) {
        document.getElementById("ctl00_ContentPlaceHolder3_hfEventTriggered").value = "1";
    }
}

/* Below lines are added by 'Imran gani' on 01-Nov-2012, for chart image preview*/
function imageOver(e) { 
    xOffset = 0;
    yOffset = 20;
    $("body").append("<p id='preview'><img id='imgPreview' src='Images/ChartImages/ChartPreview/" + document.getElementById("ctl00_ContentPlaceHolder3_ddlChartType").value + ".jpg' alt='Image preview' /></p>");
        $("#preview")
            .css("top", (e.pageY - xOffset) + "px")
            .css("left", (e.pageX + yOffset) + "px")
            .fadeIn("slow");
    }

    function imageMove(e) {
        $("a.preview").mousemove(function (e) {
            xOffset = 0;
            yOffset = 20;
            $("#preview")
        .css("top", (e.pageY - xOffset) + "px")
        .css("left", (e.pageX + yOffset) + "px");
        });
    }

function imageOut() {
    $("#preview").remove();
}

function passWidgetParameter(img) { // Implemented by 'Imran Gani' on 01-Aug-2013, to handle dashboard parameters
    if ($("div[id^=ctl00_ContentPlaceHolder3_Param_]") != null) {
        var divInputs = $("div[id^=ctl00_ContentPlaceHolder3_Param_] :input");
        for (var i = 0; i < divInputs.length; i++) {
            if (divInputs[i].type != "button") {
                //if (!img.href.contains("&" + divInputs[i].id.substring(divInputs[i].id.indexOf("["), divInputs[i].id.lastIndexOf("]") + 1).replace(" ", "_") + "=" + escape(divInputs[i].value)))
                //    img.href += "&" + divInputs[i].id.substring(divInputs[i].id.indexOf("["), divInputs[i].id.lastIndexOf("]") + 1).replace(" ", "_") + "=" + escape(divInputs[i].value);
                if (!img.href.contains("&" + divInputs[i].id.replace("ctl00_ContentPlaceHolder3_", "") + "=" + escape(divInputs[i].value)))  // Added by 'Imran Gani' on 05-Jan-2014, to set parameters values in URL
                    img.href += "&" + divInputs[i].id.replace("ctl00_ContentPlaceHolder3_", "") + "=" + escape(divInputs[i].value);
            }
        }
    }
}

function validateTextContent() {
    var selectedvalue = "";
    try {
        if (document.getElementById("ctl00_ContentPlaceHolder3_ddlChartType") != null) {
            selectedvalue = document.getElementById("ctl00_ContentPlaceHolder3_ddlChartType").value;
        }
        if (selectedvalue == "text") {
            if (document.getElementById("ctl00_ContentPlaceHolder3_txtTextContent").value == "") {
                $("#ctl00_ContentPlaceHolder3_lblmessage").html("<div class=\"mbErrorMessage\"><img id=\"imgInfo\" src=\"Images/info.gif\" alt=\"Information\" /> &nbsp;Text Content cannot be empty for text chart.</div>");
                return false;
            }
        }
        return true;
    }
    catch (err) { }
}